package service

import (
	"RocFamilySystem/internal/repository"
	"RocFamilySystem/models"
)

type SysPermissionService struct {
	SysPermissionRepository *repository.SysPermissionRepository
}

// 初始化
func init() {
	registerContainer["SysPermissionService"] = &SysPermissionService{}
}

// SetRepository 设置持久层
func (service *SysPermissionService) SetRepository(sysPermissionRepository *repository.SysPermissionRepository) {
	service.SysPermissionRepository = sysPermissionRepository
}

// AddSysPermission 添加系统权限
func (service *SysPermissionService) AddSysPermission(sysPermission *models.SysPermission) {
	service.SysPermissionRepository.InsertSysPermission(sysPermission)
}

// BatchAddSysPermission 添加系统权限
func (service *SysPermissionService) BatchAddSysPermission(sysPermissions []models.SysPermission) {
	service.SysPermissionRepository.BatchInsertSysPermission(sysPermissions)
}

// RemoveSysPermission 删除系统权限
func (service *SysPermissionService) RemoveSysPermission(sysPermissionId int) {
	service.SysPermissionRepository.DeleteSysPermission(sysPermissionId)
}

// RemoveSysPermissionBatch 批量删除系统权限
func (service *SysPermissionService) RemoveSysPermissionBatch(ids []string) {
	service.SysPermissionRepository.DeleteSysPermissionBatch(ids)
}

// ModifySysPermission 修改系统权限
func (service *SysPermissionService) ModifySysPermission(sysPermission *models.SysPermission) {
	service.SysPermissionRepository.UpdateSysPermission(sysPermission)
}

// QuerySysPermission 查询系统权限
func (service *SysPermissionService) QuerySysPermission(sysPermission *models.SysPermission, pageNum, pageSize int) PageInfo {
	tables, total := service.SysPermissionRepository.SelectSysPermission(sysPermission, pageNum, pageSize)
	return toPageInfo(pageNum, pageSize, total, tables)
}

// QuerySysPermissionById 通过ID查询系统权限
func (service *SysPermissionService) QuerySysPermissionById(id int) models.SysPermission {
	return service.SysPermissionRepository.SelectSysPermissionById(id)
}
